<?php 
include ('./_config.inc.php');


//  https://linuxcounter.net/mcert/249600.html
//  300 x 100
$template = $lico['abs_path']."/gfx/signature.image.template.002.png";
$cert     = $lico['abs_path']."/certs/".intval($_GET['a'])."m.png";

$update = 0;
if (file_exists($cert) && filemtime($cert) <= (time()-1800)) {
  $update = 1;
} else if (file_exists($cert) && filemtime($cert) >= (time()-1800)) {
  $update = 0;
} else if (!file_exists($cert)) {
  $update = 1;
}


if ($update == 1) {
  $select = "SELECT * FROM `machines` WHERE `f_key`='".lico_ESC(intval($_GET['a']))."'";
  $selmach = $db->unbuffered_query_first($select);
  if (isset($selmach[0]) && intval($selmach[0]) >= 1) {
    
    header('Content-type: image/png');
    $imNeu = ImageCreateFromPNG ($template);
    $black = ImageColorAllocate ($imNeu, 0, 0, 0); 
    imagestring($imNeu, 3, 95, 55, "Registered Linux", $black);
    imagestring($imNeu, 3, 95, 70, "machine #".$selmach[0]."", $black);
    imagepng($imNeu, $cert);
    
    $image = file_get_contents($cert);
    echo $image;
    
  } else {
    echo "Machine not found!";
    exit;
  }
} else {
  header('Content-type: image/png');
  $image = file_get_contents($cert);
  echo $image;
}


?>
